# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
        def dfs(l,r,i):
            if not l and not r and not i: return
            s= (l.val if l else 0)+ (r.val if r else 0) +i
            node = ListNode(s%10)
            node.next = dfs(l.next if l else None, r.next if r else None, s//10)
            return node
        return dfs(l1,l2,0)
'''
i用来保存进位
当前位的值是(l1.val + l2.val + i) % 10
进位值(l1.val + l2.val + i) / 10
建立新node，进位传递给下一个node
用and确保所有条件遍历完成
'''